/**

 @Name：客户短信配置
 @Author：zjl
 @License：GPL-2

 */


layui.define(['table', 'form', 'element'], function(exports){
    var $ = layui.$
        ,admin = layui.admin
        ,view = layui.view
        ,table = layui.table
        ,form = layui.form
        ,element = layui.element;

    table.render({
        elem: '#tasklog'
        ,url: layui.setter.HOST+'smstasklogs' //模拟接口
        ,cols: [[
            {type: 'numbers', fixed: 'left'}
            ,{field: 'name', width: 80, title: '客户名称'}
            ,{field: 'type', width: 80, title: '短信类型'}
            ,{field: 'task_id', width: 80, title: '任务号'}
            ,{field: 'order_id', width: 80, title: '订单号'}
            ,{field: 'origin_name', width: 80, title: '下发途径'}
            ,{field: 'mobile', width: 80, title: '手机号'}
            ,{field: 'num', width: 80, title: '号码/计费数'}
            ,{field: 'sign_content', width: 80, title: '内容'}
            ,{field: 'create_time', width: 80, title: '时间'}
            ,{field: 'status', width: 80, title: '状态', templet: '#buttonTpl', minWidth: 80, align: 'center'}
            ,{field: 'ext_code', width: 80, title: '子码'}
            ,{field: 'at_time', width: 80, title: '定时时间'}
            ,{field: 'is_tpl_sms', width: 80, title: '模板短信'}
            ,{field: 'template_code', width: 80, title: '模板编号'}
            ,{field: 'template_param', width: 80, title: '模板参数'}
            ,{field: 'ip', width: 80, title: 'IP'}
        ]]
        ,page: true
        ,limit: 10
        ,limits: [10, 15, 20, 25, 30]
        ,text: {
            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
        }
        ,size: 'sm'
        ,done: function(){
            element.render('progress');
        }
    });
    //监听搜索
    form.on('submit(task-search)', function(data){
        var field = data.field;
        var sms_type_id = $('.active')[0].dataset.sms_type_id;
        var origin_id   = $('.active')[1].dataset.origin_id;
        var is_tpl_sms  = $('.active')[2].dataset.is_tpl_sms;
        var status      = $('.active')[3].dataset.status;
        var create_time = $('.active')[4].dataset.create_time;
        field['sms_type_id'] = sms_type_id;
        field['origin_id'] = origin_id;
        field['is_tpl_sms'] = is_tpl_sms;
        field['status'] = status;
        field['create_time'] = create_time;
        //执行重载
        table.reload('tasklog', {
            where: field
            ,page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    });
    //重置
    $('.searchReset').on('click',function () {
        form.val("sms-form-task", {
            "name": ""
        })
    });
    $('.searchShow').on('click',function () {
        if($('.searchList').css('display') == 'none'){
            $('.searchList').css('display','block');
            $('.searchShow label').text('收起筛选');
            $('.searchShow i').removeClass('layui-icon-down');
            $('.searchShow i').addClass('layui-icon-up');
        }else{
            $('.searchList').css('display','none');
            $('.searchShow label').text('打开筛选');
            $('.searchShow i').removeClass('layui-icon-up');
            $('.searchShow i').addClass('layui-icon-down');
        }
    });
    $('.searchList li').on('click',function () {
        $(this).parent().children().removeClass('active');
        $(this).addClass('active');
        var name        = $('.searchInput').val();
        var sms_type_id = $('.active')[0].dataset.sms_type_id;
        var origin_id   = $('.active')[1].dataset.origin_id;
        var is_tpl_sms  = $('.active')[2].dataset.is_tpl_sms;
        var status      = $('.active')[3].dataset.status;
        var create_time = $('.active')[4].dataset.create_time;
        //执行重载
        table.reload('tasklog', {
            where: {name:name,sms_type_id:sms_type_id,origin_id:origin_id,is_tpl_sms:is_tpl_sms,status:status,create_time:create_time}
            ,page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    });
    exports('smstask', {})
});